package com.ehome.poct.backend.controller.log;

import com.ehome.core.page.Page;
import com.ehome.poct.backend.serivce.LogSerivce;
import com.ehome.poct.base.api.dto.log.TestDeviceSyncLogRecordDTO;
import com.ehome.poct.base.api.feign.log.TestDeviceLogFeginClient;
import com.ehome.poct.base.api.qry.ErrorLogQry;
import com.ehome.poct.base.api.qry.LogSyncRecordQry;
import com.ehome.poct.base.api.vo.log.SyncLogRecordListVO;
import com.ehome.poct.base.api.vo.log.TestDeviceErrorLogVO;
import com.ehome.poct.base.api.vo.log.TestDeviceSyncLogRecordVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "日志管理")
@ApiSupport(author = "路飞")
@RestController
@RequestMapping("/test_log")
public class LogController {

    @Autowired
    TestDeviceLogFeginClient testDeviceLogFeginClient;
    @Autowired
    LogSerivce logSerivce;


    @ApiOperation("错误日志列表")
    @ApiOperationSupport(author = "路飞", order = 1)
    @GetMapping("/error_log")
    public Page<TestDeviceErrorLogVO> getErrorLog(ErrorLogQry qry){
        Page<TestDeviceErrorLogVO> page = logSerivce.getErrorLog(qry);
        return page;
    }

    @ApiOperation("日志清单列表")
    @ApiOperationSupport(author = "路飞", order = 2)
    @GetMapping("/log_list")
    public SyncLogRecordListVO getLogList(@RequestParam String sno) {
        return logSerivce.getLogList(sno);
    }

    @ApiOperation("日志同步记录")
    @ApiOperationSupport(author = "路飞", order = 3)
    @GetMapping("/log_sync_record")
    public List<TestDeviceSyncLogRecordVO> getLogSyncRecord(LogSyncRecordQry qry){
        return logSerivce.getLogSyncRecord(qry);
    }

    @ApiOperation("通过ID获取日志同步记录")
    @ApiOperationSupport(author = "路飞", order = 4)
    @GetMapping("/log_sync_record/{id}")
    public TestDeviceSyncLogRecordVO getLogSyncRecordById(@PathVariable(value = "id") Long id){
        return logSerivce.getLogSyncRecordById(id);
    }

    @ApiOperation(value = "同步日志")
    @ApiOperationSupport(author = "路飞", order = 5)
    @PostMapping("/sync_log")
    public TestDeviceSyncLogRecordVO syncLog(@RequestBody @Validated TestDeviceSyncLogRecordDTO dto){
       return logSerivce.syncLog(dto);
    }

    @ApiOperation(value = "批量同步日志")
    @ApiOperationSupport(author = "路飞", order = 6)
    @PostMapping("/sync_log/batch")
    public TestDeviceSyncLogRecordVO batchSyncLog(@RequestBody List<TestDeviceSyncLogRecordDTO> list){
       return logSerivce.batchSyncLog(list);
    }

    @ApiOperation(value = "重新同步日志")
    @ApiOperationSupport(author = "路飞", order = 7)
    @PostMapping("/again_sync_log")
    public void againSyncLog(@RequestBody TestDeviceSyncLogRecordDTO dto){
        logSerivce.againSyncLog(dto);
    }
}
